﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using AJArt.Mvc.Models;

namespace AJArt.Mvc.Controllers
{
    public class HomeController : Controller
    {
        public IRazorService RazorService { get; set; }

        protected override void Initialize(RequestContext requestContext)
        {
            if (RazorService == null) { RazorService = new RazorService(); }

            base.Initialize(requestContext);
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Generate()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Generate(RazorModel model)
        {
            if (ModelState.IsValid)
            {
                if (RazorService.GenerateSite())
                {
                    return RedirectToAction("GenerateSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "Something wrong was occurred.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

        public ActionResult GenerateSuccess()
        {
            return View();
        }
    }
}
